from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager
from flask_sockets import Sockets
from redis import Redis
import rq

db = SQLAlchemy()
jwt = JWTManager()
sockets = Sockets()
redis = None
rq_queue = None

def init_extensions(app):
    global redis, rq_queue
    
    # 初始化数据库
    db.init_app(app)
    
    # 初始化JWT
    jwt.init_app(app)
    
    # 初始化WebSocket
    sockets.init_app(app)
    
    # 初始化Redis
    redis = Redis(
        host=app.config['REDIS_HOST'],
        port=app.config['REDIS_PORT'],
        db=app.config['REDIS_DB'],
        decode_responses=True
    )
    
    # 初始化任务队列
    rq_queue = rq.Queue('im_tasks', connection=redis)